//
//  LDMainTabBarController.swift
//  Weibo201655
//
//  Created by pro on 16/5/5.
//  Copyright © 2016年 LeeDan. All rights reserved.
//

import UIKit

class LDMainTabBarController: UITabBarController, LDTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //设置tabbar
        let tb = LDTabBar()
        tb.tabBarDelegate = self
        setValue(tb, forKey: "tabBar")
        
        //添加子控制器
        addChildViewController()
    }
    
    //MRRK: 添加子控制器
    func addChildViewController() {
        
        //首页
        let homeVC = LDHomeTableViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        // 消息
        let messageVC = LDMessageTableViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        // 占位的tabBar
        addChildViewController(UIViewController())
        
        // 发现
        let discoverVC = LDDiscoverTableViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        // 我
        let profileVC = LDProfileTableViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    func addChildViewController(controller: UIViewController, title: String, imageName: String) {
        
        //文字
        controller.title = title
        //文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        //图片
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //添加控制器
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
    }
    
    //MARK: tabbar代理方法
    func tabBarPlusButtonAction() {
        print("tabBarPlusButtonAction")
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
